<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        let arr = ['2','dd','fff','555']
        for(let key in arr) {
        //fro..in 输出的key是索引
            console.log(key);
        }
        for (let value of arr) {
            //for...of输出的是值
            //注意：of迭代的对象必须有一个[Symbol.iterator] 方法
            console.log(value);
        }
    console.log(arr);


    // let obj = {
    //     name:'ff',
    //     age:67
    // }
    // for(let value of obj) {
    //     //obj没有[Symbol.iterator] 方法  不能使用 
    //     console.log(value);
    // }


    //改造对象可以使用for...of
    let newObj = {
        name:'nn',
        age:90
    }
    newObj[Symbol.iterator] = function () {
        let newArr = Object.keys(newObj);//['name','age']
        let len = newArr.length;
        let n = -1;
        return {
             next:function () {
                n++;
                 if (n < len) {
                    return {
                        value:newObj[newArr[n]],
                        done:false
                    }
                 } else {
                     return {
                        done:true
                     }
                 }
                 
             }
        }
    }
    for (let value of newObj) {
        console.log(value);
    }
    </script>
</body>
</html>